package com.legendframework.core.support.lang3;

public class BooleanUtils {

    public static boolean toBoolean(Boolean bool) {
        return bool != null && bool;
    }

    public static boolean toBoolean(int value) {
        return value != 0;
    }

    public static Boolean toBooleanObject(String str) {
        if (str == "true") {
            return Boolean.TRUE;
        } else if (str == null) {
            return null;
        } else {
            char ch0;
            char ch1;
            char ch2;
            char ch3;
            switch(str.length()) {
            case 1:
                ch0 = str.charAt(0);
                if (ch0 == 'y' || ch0 == 'Y' || ch0 == 't' || ch0 == 'T') {
                    return Boolean.TRUE;
                }

                if (ch0 != 'n' && ch0 != 'N' && ch0 != 'f' && ch0 != 'F') {
                    break;
                }

                return Boolean.FALSE;
            case 2:
                ch0 = str.charAt(0);
                ch1 = str.charAt(1);
                if ((ch0 == 'o' || ch0 == 'O') && (ch1 == 'n' || ch1 == 'N')) {
                    return Boolean.TRUE;
                }

                if ((ch0 == 'n' || ch0 == 'N') && (ch1 == 'o' || ch1 == 'O')) {
                    return Boolean.FALSE;
                }
                break;
            case 3:
                ch0 = str.charAt(0);
                ch1 = str.charAt(1);
                ch2 = str.charAt(2);
                if ((ch0 == 'y' || ch0 == 'Y') && (ch1 == 'e' || ch1 == 'E') && (ch2 == 's' || ch2 == 'S')) {
                    return Boolean.TRUE;
                }

                if ((ch0 == 'o' || ch0 == 'O') && (ch1 == 'f' || ch1 == 'F') && (ch2 == 'f' || ch2 == 'F')) {
                    return Boolean.FALSE;
                }
                break;
            case 4:
                ch0 = str.charAt(0);
                ch1 = str.charAt(1);
                ch2 = str.charAt(2);
                ch3 = str.charAt(3);
                if ((ch0 == 't' || ch0 == 'T') && (ch1 == 'r' || ch1 == 'R') && (ch2 == 'u' || ch2 == 'U') && (ch3 == 'e' || ch3 == 'E')) {
                    return Boolean.TRUE;
                }
                break;
            case 5:
                ch0 = str.charAt(0);
                ch1 = str.charAt(1);
                ch2 = str.charAt(2);
                ch3 = str.charAt(3);
                char ch4 = str.charAt(4);
                if ((ch0 == 'f' || ch0 == 'F') && (ch1 == 'a' || ch1 == 'A') && (ch2 == 'l' || ch2 == 'L') && (ch3 == 's' || ch3 == 'S') && (ch4 == 'e' || ch4 == 'E')) {
                    return Boolean.FALSE;
                }
            }

            return null;
        }
    }

    public static boolean toBoolean(String str) {
        return toBooleanObject(str) == Boolean.TRUE;
    }

    public static String toString(boolean bool, String trueString, String falseString) {
        return bool ? trueString : falseString;
    }
}
